-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Support full Google GenAI client options (support Vertex AI as alternative to Gemini API key) #1130
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
🦋 Changeset detectedLatest commit: a7ee673 The changes in this PR will be included in the next version bump. This PR includes changesets to release 2 packages
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Greptile Overview
Summary
This PR updates the Google GenAI client to accept the full GoogleGenAIOptions type instead of a simplified ClientOptions interface, enabling Vertex AI authentication and region control.
Key Changes:
- Updated
ClientOptionstype intypes/model.tsto includeGoogleGenAIClientOptionsas a union member - Added intersection type with aisdk options (
apiKey?,baseURL?) to support AI SDK language model providers - Modified
GoogleClient.tsto importGoogleGenAIOptionsdirectly from@google/genaiand pass the full options object to the client constructor - Implementation now matches the pattern used by
AnthropicClientandOpenAIClient, which pass their full client options verbatim
Potential Concern:
The intersection type on lines 48-57 of types/model.ts adds apiKey?: string and baseURL?: string to all client options. If GoogleGenAIOptions already defines these properties with different types, this could cause type conflicts. However, since the PR author states this is a typing-only change with no runtime impact, this suggests the properties are compatible.
Confidence Score: 4/5
- This PR is safe to merge with minimal risk - it's a type-only change that expands functionality without breaking existing code.
- Score reflects the low-risk nature of the change (type definitions only), proper documentation via changeset, and consistent pattern matching with other client implementations. One point deducted due to potential type intersection conflicts with the added
apiKey?andbaseURL?properties in the union type - while likely compatible, this wasn't explicitly verified in the PR. - Pay attention to
types/model.ts- verify that the intersection type with aisdk options doesn't conflict with existingGoogleGenAIOptionsproperties.
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| types/model.ts | 4/5 | Updated ClientOptions type to include full GoogleGenAIClientOptions and added intersection with aisdk options (apiKey, baseURL). The intersection type may cause type conflicts if GoogleGenAIOptions already defines these properties. |
| lib/llm/GoogleClient.ts | 5/5 | Switched from local ClientOptions import to GoogleGenAIOptions directly from @google/genai. Changed constructor to pass full clientOptions to GoogleGenAI instead of just apiKey. Clean implementation that matches the pattern used by Anthropic and OpenAI clients. |
Sequence Diagram
sequenceDiagram
participant User
participant Stagehand
participant LLMProvider
participant GoogleClient
participant GoogleGenAI
User->>Stagehand: Initialize with modelClientOptions
Stagehand->>LLMProvider: getClient(modelName, clientOptions)
LLMProvider->>GoogleClient: new GoogleClient({clientOptions})
Note over GoogleClient: clientOptions now supports full GoogleGenAIOptions
GoogleClient->>GoogleClient: Check for apiKey in clientOptions
alt apiKey missing
GoogleClient->>GoogleClient: loadApiKeyFromEnv()
end
GoogleClient->>GoogleGenAI: new GoogleGenAI(clientOptions)
Note over GoogleGenAI: Full options passed (apiKey, location, project, etc.)
GoogleGenAI-->>GoogleClient: client instance
GoogleClient-->>LLMProvider: GoogleClient instance
LLMProvider-->>Stagehand: LLMClient
User->>Stagehand: createChatCompletion()
Stagehand->>GoogleClient: createChatCompletion()
GoogleClient->>GoogleGenAI: models.generateContent()
GoogleGenAI-->>GoogleClient: response
GoogleClient-->>Stagehand: LLMResponse
Stagehand-->>User: result
2 files reviewed, no comments
108b73a to
ddd8a1a
Compare
|
If in the future you want to only support the AI SDK (basing this off #1129 (comment)), this is also possible, but typing will need to be expanded to allow passing other options than simply an API key and base URL: Docs: |
1968b25 to
aaf728e
Compare
aaf728e to
a7ee673
Compare
why
what changed
I updated the typing of
ClientOptionsto support the full Google GenAI client constructor options, just like the Anthropic and OpenAI client options are already passed verbatim.Because the Google GenAI client options don't have a
baseUrlkey, I also added explicit typing for the client options used for the ai-sdk model provider.test plan
As this is only a typing change, I foresaw no immediate need for unit tests. Authentication with VertexAI is already tested as part of the GenAI client package.